FROM maven:3-amazoncorretto-21-alpine AS build
WORKDIR /app
RUN mkdir -p /root/.m2 && \
    echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" \
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 \
                              http://maven.apache.org/xsd/settings-1.0.0.xsd"> \
    <mirrors> \
      <mirror> \
        <id>aliyun-public</id> \
        <mirrorOf>central</mirrorOf> \
        <name>Aliyun Public Repository</name> \
        <url>https://maven.aliyun.com/repository/public</url> \
      </mirror> \
      <mirror> \
        <id>aliyun-central</id> \
        <mirrorOf>central</mirrorOf> \
        <name>Aliyun Central Repository</name> \
        <url>https://maven.aliyun.com/repository/central</url> \
      </mirror> \
    </mirrors> \
    </settings>' > /root/.m2/settings.xml
COPY pom.xml .
RUN mvn dependency:go-offline -DskipTests
COPY src src
RUN mvn package -DskipTests

FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
CMD ["java", "-jar", "app.jar"]

